﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using TamTreSoSinh.DBContext;

namespace TamTreSoSinh.UC
{
    public partial class SlidebarPart : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DBTamTreEntities datacontext = new DBTamTreEntities();
            List<SlidebarInfo> listSlidebarInfo = datacontext.SlidebarInfoes.OrderBy(obj => obj.Priority).ToList();
            //List<SlidebarContent> listSlidebarContent = new List<SlidebarContent>();
            //listSlidebarContent.Add(new SlidebarContent()
            //    {
            //        Title = @"Welcome to BEAUTYSPOT",
            //        ImagePath = @"/images/slide_01.jpg",
            //        ImageAlign = "right",
            //        ContentAlign = "left",
            //        Content = @"<h1>Welcome<br>to BEAUTYSPOT!</h1><h3>HTML Template for Beauty Salons,<br>Hairdressers, Wellness or Spa</h3>"
            //    });

            //listSlidebarContent.Add(new SlidebarContent()
            //{
            //    Title = @"20% off All Massages",
            //    ImagePath = @"/images/slide_02.jpg",
            //    ImageAlign = "left",
            //    ContentAlign = "right",
            //    Content = @"<h2>20% Off<br>All Massages</h2><h3>This Friday Only!<br> <a class='m-open-ajax-modal' href='http://demos.volovar.net/beautyspot.html/demo/ajax/reservation-form.html'> Make a Reservation</a></h3>"
            //});

            //listSlidebarContent.Add(new SlidebarContent()
            //{
            //    Title = @"Eshop Launched",
            //    ImagePath = @"/images/slide_03.jpg",
            //    ImageAlign = "right",
            //    ContentAlign = "left",
            //    Content = @"<h2>Eshop<br>Launched</h2><h3><a href='http://demos.volovar.net/beautyspot.html/demo/shop-list.html'> Take a Look</a>at Our Products</h3>"
            //});


            rptSlidebar.DataSource = listSlidebarInfo;
            rptSlidebar.DataBind();
        }

        protected void rptSlidebar_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            HtmlGenericControl div = (HtmlGenericControl)e.Item.FindControl("divSlideBar");
            int index = e.Item.ItemIndex + 1;
            SlidebarInfo slidebarContent = (SlidebarInfo)e.Item.DataItem;
            div.Attributes["class"] = "slide slide-" + index + " m-bg-align-" + slidebarContent.ImageAlign;
            div.Attributes["style"] = @"background-image: url('" + slidebarContent.ImagePath + "')";
            div.Attributes["data-label"] = slidebarContent.Title;

            div = (HtmlGenericControl)e.Item.FindControl("divSlideBarContent");
            div.Attributes["class"] = "slide-content various-content textalign-" + slidebarContent.ContentAlign +" valign-middle";
            div.InnerHtml = slidebarContent.SlideContent;
        }
    }
}